package game.model
{
	import flash.geom.Point;
	
	import game.model.type.Enum;
	import game.model.type.NoticeCMD;
	public class GameData
	{
		private static var s_instance:GameData;
		private static var isSing:Boolean=false;
		/**true继续跳**/
		public var isJxToJ:Boolean=false;
		/**true:可以点击跳**/
		public var isToJump:Boolean=false;
		/**上一关**/
		public var proLeId:int=0;
		/**关卡ID 1-6**/
		public var myLevelId:int=1;
		public var lookId:int=Enum.no_num;
		/**跳一跳结果**/
		public var resultData:Object=null;
		public var lostData:Object=null;
		/**地图是否在移动 true是**/
		public var isMapMove:Boolean=false;
		/**自动跳跃到关卡 index 1-->6**/
		public var automaticIndex:int=Enum.no_num;
		/**true已经登录**/
		public var isLogin:Boolean=false;
		/**每次花费**/
		public var playMoney:Number=0;
		/**关卡数据**/
		public var levelList:Array=[{awardId:Enum.no_num},{awardId:Enum.no_num},{awardId:Enum.no_num},{awardId:Enum.no_num},{awardId:Enum.no_num},{awardId:Enum.no_num}];
		/**人 起点，命中，掉落**/
		public var peoXyList:Array=[{x:192,y:503},{x:528,y:368},{x:433,y:442}];
		/**关卡地图XY,0,1,2,3,4,5,6**/
		public var levelGsXyList:Array=[{x:386,y:214},{x:-57,y:407},{x:-484,y:598},{x:-924,y:796},{x:-1353,y:987},{x:-1790,y:1182}];
		public function GameData()
		{
			if(!isSing){
				throw new Error("GameData 只能实例一次");
			}
			
		}
		public static function get instance():GameData {
			if (s_instance == null){
				isSing=true;
				s_instance = new GameData();
				isSing=false;
			}
			return s_instance;
		}
		
		
		
		public function CMD(data:Object):void{
			//trace('GameData CMD',JSON.stringify(data),this.hasOwnProperty(data.cmd));
			if(this.hasOwnProperty(data.cmd)){
				//this[data.cmd](data.content);
				this[data.cmd](data);
			}
			
		}
		/**登录应答,场景切换**/
		public function Panle(data:Object):void{
			//trace('GameData Panle',JSON.stringify(data));
			trace('GameData Panle',data.content.myLevelId);
			isLogin=true;
			isToJump=true;
			
			myLevelId=data.content.myLevelId+1;
			proLeId=myLevelId-1;
			playMoney=data.content.money;
			levelList=data.content.levelList;
		}
		
		public function Result(data:Object):void{
			if(data==null){
				data={
					status:0,
					content:{}
				}
			}
			if(data.status==0){
				this.resultData=data.content;
				proLeId=myLevelId;
				myLevelId=data.content.nextLevelId
			}else{
				this.resultData=null;
			}
			if(data.status==-2){//余额不足
				
			}		
			ZooMain.event.dispatchEvent(NoticeCMD.NOTICE_SRS_automatic_change);
		}
		
		public function FailChoose(data:Object):void{
			if(data.content.type==1){
				myLevelId=1;
				proLeId=0;
				isToJump=true;
			}
			/*if(automaticIndex!=Enum.no_num){
				automaticIndex=Enum.no_num;
				ZooMain.event.dispatchEvent(NoticeCMD.NOTICE_SRS_automatic_change);
			}*/
		}
		
		public function UpdLevelInfo(data:Object):void{
			for(var i:int=0;i<levelList.length;i++ ){
				if(data.content.levelId==levelList[i].levelId){
					if(data.content.hasOwnProperty('succRatio')){
						levelList[i].succRatio=data.content.succRatio;
					}
					if(data.content.hasOwnProperty('holdNick')){
						levelList[i].holdNick=data.content.holdNick;
					}
				}
			}
		}
		
		public function Choose(data:Object):void{
			if(data.content.type==1){
				myLevelId=1;
				proLeId=0;
				isToJump=true;
				
				if(automaticIndex!=Enum.no_num){
					automaticIndex=Enum.no_num;
					ZooMain.event.dispatchEvent(NoticeCMD.NOTICE_SRS_automatic_change);
				}
			}
			
		}
		
		
	}
}